package com.example.yjhmatch.controller;


import com.example.common.vo.Result;
import com.example.yjhmatch.mapper.StatisticsMapper;
import com.example.yjhmatch.service.IStatisticsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.yjh.entity.Statistics;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 廖老师
 * @since 2023-07-21
 */
@RestController
@RequestMapping("/yjh/statistics")
public class StatisticsController {
    @Resource
    StatisticsMapper statisticsMapper;

    @Resource
    IStatisticsService statisticsService;

    @RequestMapping("selectByMatchId")
    public Result selectByMatchId(@RequestParam("mid") String mid){
        return Result.success("查询成功",statisticsMapper.selectByMatchId(mid));
    }


    @RequestMapping("selectSumKills")
    public Result selectSumKills(@RequestParam("round") Integer round,
                                 @RequestBody String name){
        return Result.success("查询成功",statisticsMapper.selectSumKills(round,name));
    }

    @RequestMapping("selectAllStatistics")
    public PageInfo<Statistics> selectAllStatistics(@RequestParam int current){
        //获取第1页，10条内容，默认查询总数count
        PageHelper.startPage(current, 7);
        List<Statistics> list = statisticsService.list();
        //用PageInfo对结果进行包装
        PageInfo page = new PageInfo(list);
        return page;
    }
    @RequestMapping("selectTotal")
    public Long selectTotal(){
        return statisticsService.lambdaQuery().count();
    }

    @RequestMapping("orderBySumKills")
    public List orderBySumKills(){
        return statisticsMapper.orderBySumKills();
    }

    @RequestMapping("orderBySumAssists")
    public List orderBySumAssists(){
        return statisticsMapper.orderBySumAssists();
    }

    @RequestMapping("orderBySumMinionsKilled")
    public List orderBySumMinionsKilled(){
        return statisticsMapper.orderBySumMinionsKilled();
    }

    @RequestMapping("orderBySumMoney")
    public List orderBySumMoney(){
        return statisticsMapper.orderBySumMoney();
    }

    @RequestMapping("orderBySumBanHero")
    public List orderBySumBanHero(){
        return statisticsMapper.orderBySumBanHero();
    }

    @RequestMapping("orderBySumPickHero")
    public List orderBySumPickHero(){
        return statisticsMapper.orderBySumPickHero();
    }

    @RequestMapping("addStatistic")
    public Result addStatistic(@RequestBody Statistics statistics){
        return Result.success("添加成功",statisticsService.saveOrUpdate(statistics));
    }
    @RequestMapping("selectByPlayerId")
    public Result selectByPlayerId(@RequestParam("player_id") String playerId){
        return Result.success("查询成功",statisticsMapper.selectByPlayerId(playerId));
    }

}

